今天整個忙翻,回到家打開電腦已經22:30左右
逼自己要在12:00前po廢文
給你自己承諾要堅持下去
怕來不及po文,因此今天題目比較簡單些
挑戰的是Codewars LV7的題目
題目:
An isogram is a word that has no repeating letters, consecutive or non-consecutive. Implement a function that determines whether a string that contains only letters is an isogram. Assume the empty string is an isogram. Ignore letter case.
is_isogram("Dermatoglyphics" ) == true
is_isogram("aba" ) == false
is_isogram("moOse" ) == false # -- ignore letter case
def is_isogram(string)
#your code here
end
Test.assert_equals(is_isogram("Dermatoglyphics"), true )
Test.assert_equals(is_isogram("isogram"), true )
Test.assert_equals(is_isogram("aba"), false, "same chars may not be adjacent" )
Test.assert_equals(is_isogram("moOse"), false, "same chars may not be same case" )
Test.assert_equals(is_isogram("isIsogram"), false )
Test.assert_equals(is_isogram(""), true, "an empty string is a valid isogram" )
答案:
def isIsogram(string)
# if string.downcase.chars.uniq == string.downcase.chars
# true
# else
# false
# end
# return true if string.downcase.chars.uniq == string.downcase.chars
# false
string.downcase.chars.uniq == string.downcase.chars
end
本文同步發布於 小菜的 Blog https://riverye.com/